package com.mycompany.rest.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.mycompany.rest.domain.Destino;

@Service("destinoService")
public class DestinoService {


protected static Logger logger = Logger.getLogger("service");
	
	// In-memory list
	private List<Destino> destinos = new ArrayList<Destino>();
	
	public DestinoService() {
		logger.debug("Init database");
		
		// Create in-memory list
		Destino d1= new Destino();
		d1.setId((long)1);
		d1.setDescripcion("Lima");
		
		Destino d2= new Destino();
		d2.setId((long)2);
		d2.setDescripcion("Arequipa");
		
		Destino d3= new Destino();
		d3.setId((long)3);
		d3.setDescripcion("Trujillo");
		
		Destino d4= new Destino();
		d4.setId((long)4);
		d4.setDescripcion("Piura");
		
		destinos.add(d1);
		destinos.add(d2);
		destinos.add(d3);
		destinos.add(d4);
	}
	
	/**
	 * Retrieves all persons
	 */
	public List<Destino> getAll() {
		logger.debug("Retrieving all persons");
		
		return destinos;
	}
	
	/**
	 * Retrieves a single person
	 */
	public Destino get( Long id ) {
		logger.debug("Retrieving person with id: " + id);
		
		for (Destino destino:destinos) {
			if (destino.getId().longValue() == id.longValue()) {
				logger.debug("Found record");
				return destino;
			}
		}
		
		logger.debug("No records found");
		return null;
	}
	
}
